# 学生出勤记录 I

给定一个字符串来代表一个学生的出勤记录,这个记录仅包含以下三个字符:

'A' : Absent,缺勤
'L' : Late,迟到
'P' : Present,到场
如果一个学生的出勤记录中不超过一个'A'(缺勤)并且不超过两个连续的'L'(迟到),那么这个学生会被奖赏。

你需要根据这个学生的出勤记录判断他是否会被奖赏。

示例 1:

输入: "PPALLP"
输出: True
示例 2:

输入: "PPALLL"
输出: False

#

// stringObject.indexOf(searchvalue,fromindex)  searchvalue:必需。规定需检索的字符串值;fromindex:可选的整数参数。规定在字符串中开始检索的位置。它的合法取值是 0 到 stringObject.length - 1。如省略该参数,则将从字符串的首字符开始检索。
var checkRecord = function (s) {
  let indexOfA = s.indexOf("A"),
    indexOfL = s.indexOf("LLL");
  if (indexOfL > -1) return false;
  if (indexOfA > -1) {
    if (s.indexOf("A", indexOfA + 1) > -1) return false;
  }
  return true;
};

#

var checkRecord = function(s) {
  var posL = s.indexOf("LLL") , posA = s.indexOf("A")
  if(posL>-1) {
    return false;
  }
  if(posA>-1) {
    if(s.indexOf("A",posA+1)>-1){
      return false;
      }
  }
  return true; 
}
Last Updated: 7/5/2021, 5:41:09 PM